package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.lib.webservice.client.*;
import de.tabuma.ssoclient.entity.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.2.4.1 $
 * @since $Date: 2010/01/13 10:23:24 $
 */
public class UserFacade {
    public static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(User user, String ssoId) throws Exception {
        String methodName = "UserService_create";
        String soapAction = "UserService_create";

        Class returnType = Integer.class;
        Object params[] = {user, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        user.setId(obj.longValue());
        UserHashFacade.put(user, ssoId);
        return obj;
    }

    public static int create(User user, String ssoId, String username) throws Exception {
        String methodName = "UserService_create1";
        String soapAction = "UserService_create1";

        Class returnType = Integer.class;
        Object params[] = {user, ssoId, username};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        user.setId(obj.longValue());
        UserHashFacade.put(user, ssoId);
        return obj;
    }

    public static void update(User user, String ssoId) throws Exception {
        String methodName = "UserService_update";
        String soapAction = "UserService_update";

        Object params[] = {user, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        UserHashFacade.put(user, ssoId);
    }

    public static User get(int id, String ssoId) throws Exception {
        String methodName = "UserService_get";
        String soapAction = "UserService_get";

        Class returnType = User.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        User obj = UserHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (User) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
            UserHashFacade.put(obj, ssoId);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "UserService_remove";
        String soapAction = "UserService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        UserHashFacade.remove(id, ssoId);
    }
}
